package com.dlink.sqljobsync.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;


/**
 * 读取资源运行环境
 * @author huangjun
 */
@Component
@Slf4j
public class CustomCommandLineRunner implements CommandLineRunner {
    Environment env;


    /**
     * 获取资源环境 env
     * @param env
     */
    public CustomCommandLineRunner(Environment env) {
        this.env = env;
    }

    @Override
    public void run(String... args) throws Exception {
        log.info("启动一个资源线程池进行任务调用。。。。");
        String sessid = Objects.requireNonNull(env.getProperty("random."));
        log.info("当前获取的随机32位：" + sessid);
        Date nowTime = new Date(System.currentTimeMillis());
        SimpleDateFormat sdFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd");
        String retStrFormatNowDate = sdFormatter.format(nowTime);
        log.info("任务启动：CommandLineRunner 线程池运行时间：" + retStrFormatNowDate );
    }
}
